#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

int main() {
    pid_t pid = fork();
    if (pid == -1) {
        perror("fork error");
        exit(1);
    }

    if (pid == 0) {
        printf("I'm child pid = %d, my parent pid = %d \n", getpid(), getppid());
        sleep(10);
        printf("----------child die-----\n");
        return 1111;
    }

    if (pid > 0) {
        int status, wpid;
        wpid = wait(&status);
        if (wpid == -1) {
            perror("wait error");
            exit(1);
        }
        if (WIFEXITED(status)) {//正常退出返回真
            printf("child exit with %d\n", WEXITSTATUS(status));
        }

        if (WIFSIGNALED(status)) {
            printf("child exit with singal %d\n", WTERMSIG(status));
        }

        printf("I'm parent , wait finished,  pid = %d, my child pid = %d\n", getpid(), pid);
    }
    return 0;
}